﻿using UnityEngine;
using System.Collections;

public class GUITextureCenter : MonoBehaviour {

	private GUITexture myGUITexture;
	public Vector2 offset = new Vector2(0, 0);
	
	void Awake()
	{
		myGUITexture = this.gameObject.GetComponent("GUITexture") as GUITexture;
	}
	
	// Use this for initialization
	void Start()
	{
//		int textureHeight = guiTexture.texture.height;
//		int textureWidth = guiTexture.texture.width;
		int screenHeight = Screen.height;
		int screenWidth = Screen.width;
		float oldWidth = myGUITexture.pixelInset.width;
		float oldHeight = myGUITexture.pixelInset.height;

		float xPosition = screenWidth / 2 - (oldWidth / 2);
		float yPosition = screenHeight / 2 - (oldHeight / 2);

		myGUITexture.pixelInset = 
			new Rect(xPosition + offset.x, yPosition + offset.y, oldWidth, oldHeight);
	}

}
